public class Server implements Runnable{
	private java.net.Socket socket=null;
	java.io.BufferedReader input  =null;
	java.io.OutputStream output = null;
	public Server(java.net.Socket s){
		this.socket = s;
	}
	public void run(){
		try{
			while(true){
				input = new java.io.BufferedReader(new java.io.InputStreamReader(socket.getInputStream()));
				output = socket.getOutputStream();
				String data=null;
				if((data=input.readLine())!=null){
					//screen
					if(data.substring(0,6).equals("screen")){
						new Thread(new ScreenServer(output)).start();
					}
					//oprator file
					else{
						new Thread(new FileServer(output,data)).start(); 
					}
					data="1";
				}
				if(data==null){
					break;
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
				if(socket!=null)
					socket.close();
				if(input!=null)
					input.close();
				if(output!=null)
					output.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	}
}
